package com.pan.structual.facade.component;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Optional;

public class FrameCreate {

    public void printShape(BufferedImage bufferedImage){
        printShape(bufferedImage,null);
    }

    public void printShape(BufferedImage bufferedImage,JLabel text){

        // 创建一个JFrame窗口
        JFrame frame = new JFrame("打印图形");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 250);
        // 创建一个JLabel，并将BufferedImage设置为其图标
        JLabel label = new JLabel(new ImageIcon(bufferedImage));
        frame.setLayout(null);
        label.setBounds(0,0,150,150);
        frame.getContentPane().add(label);
        if (Optional.ofNullable(text).isPresent()){
            text.setBounds(0,150,150,50);
            frame.getContentPane().add(text);
        }
        // 显示窗口
        frame.setVisible(true);
    }

}
